﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WINAPI.User32;

namespace WeaponEvalue
{
    public partial class CrackForm : Form
    {
        private IntPtr geWindowPtr;
        private IntPtr editPtr;

         char[] code=new char[36];

        public CrackForm()
        {
            InitializeComponent();
            for(int i=0;i<26;i++)
            {
                code[i] = (char)('a'+i);
            }
            for(int i=26;i<36;i++)
            {
                code[i] =(char)('0' + i - 26);
            }
        }

        private void findWindowButton_Click(object sender, EventArgs e)
        {
            geWindowPtr = User32Dll.FindWindow(null, "[#] Granado Espada [#]");
            editPtr = User32Dll.FindWindowEx(geWindowPtr, IntPtr.Zero, "Edit", null);
            if(geWindowPtr==IntPtr.Zero|| editPtr==IntPtr.Zero)
            {
                MessageBox.Show("Windows finding error.");
            }

            for (int i = 1; i <=1000; i++)
            {
                User32Dll.SetForegroundWindow(editPtr);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYDOWN, new IntPtr(0x41), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_CHAR, new IntPtr(0x41), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYUP, new IntPtr(0x41), IntPtr.Zero);

                User32Dll.SetForegroundWindow(editPtr);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYDOWN, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_CHAR, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYUP, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);

                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYDOWN, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_CHAR, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYUP, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);

                logTextBox.Text += i + "trys\r\n";
            }
        }

        private void RunButton_Click(object sender, EventArgs e)
        {
            geWindowPtr = User32Dll.FindWindow(null, "[#] Granado Espada [#]");
            editPtr = User32Dll.FindWindowEx(geWindowPtr, IntPtr.Zero, "Edit", null);
            if (geWindowPtr == IntPtr.Zero || editPtr == IntPtr.Zero)
            {
                MessageBox.Show("Windows finding error.");
            }

            int interval1 = int.Parse(IntervalTextBox1.Text);
            int interval2 = int.Parse(IntervalTextBox2.Text);
            int count = int.Parse(CountTextBox.Text);

            for (int i = 1; i <= count; i++)
            {
                User32Dll.SetForegroundWindow(editPtr);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYDOWN, new IntPtr(Vks.VK_DOWN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_CHAR, new IntPtr(Vks.VK_DOWN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYUP, new IntPtr(Vks.VK_DOWN), IntPtr.Zero);
                Thread.Sleep(interval1);
                User32Dll.SetForegroundWindow(editPtr);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYDOWN, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_CHAR, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                User32Dll.SendMessage(editPtr, User32Dll.WM_KEYUP, new IntPtr(Vks.VK_RETURN), IntPtr.Zero);
                Thread.Sleep(interval2);
                logTextBox.Text += i + "trys\r\n";
            }
        }
    }
}